package com.example.backend.controller;


import com.example.backend.pojo.Data;
import com.example.backend.pojo.Food;
import com.example.backend.pojo.Restaurant;
import com.example.backend.pojo.Result;
import com.example.backend.service.DataService;
import com.example.backend.util.TencentCOSUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/data")
public class DataController {
    @Autowired
    private DataService dataService;
    @PostMapping("/image")//图片更新
    public Result updateAvatar(MultipartFile file) throws IOException {
//        String originalFilename = file.getOriginalFilename();
//        String filename= UUID.randomUUID().toString()+originalFilename.substring(originalFilename.lastIndexOf("."));
//        String url = AliOssUtil.uploadFile(filename, file.getInputStream());
        String url = TencentCOSUtil.upLoadFile(file);
        return  Result.success(url);
    }

    @PostMapping("daydata")
    public Result<List<Data>> daydata(Integer restaurantid){
        return  Result.success(dataService.daydata(restaurantid));
    }
    @PostMapping("monthdata")
    public Result<List<Data>> monthdata(Integer restaurantid){
        return  Result.success(dataService.monthdata(restaurantid));
    }
    @PostMapping("dayfood")
    public Result<List<Food>> dayfood(Integer restaurantid){
        return  Result.success(dataService.dayfood(restaurantid));
    }
    @PostMapping("monthfood")
    public Result<List<Food>> monthfood(Integer restaurantid){
        return  Result.success(dataService.monthfood(restaurantid));
    }

    @GetMapping("/dayres")
    public Result<List<Restaurant>> dayres(){
        return Result.success(dataService.dayres());
    }
    @GetMapping("/monthres")
    public Result<List<Restaurant>> monthres(){
        return Result.success(dataService.monthres());
    }
    @GetMapping("/allday")
    public Result<List<Data>> allday(){
        return Result.success(dataService.allday());
    }
    @GetMapping("/allmonth")
    public Result<List<Data>> allmonth(){
        return Result.success(dataService.allmonth());
    }

    @GetMapping("/allall")
    public Result<Data> allall(){
        return Result.success(dataService.allall());
    }

    @GetMapping("/allres")
    public Result<List<Data>> allres(){
        return Result.success(dataService.allres());
    }

    @PostMapping("/useralldate")
    public Result<Data> useralldate(Integer userid){
        return  Result.success(dataService.useralldate(userid));
    }

    @PostMapping("usermonthdate")
    public Result<List<Data>> usermonthdate(Integer userid){
        return  Result.success(dataService.usermonthdate(userid));
    }

}
